package com.ce.pms.system.custservice.service.impl;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.system.custservice.model.CustEventNatureDO;
import com.ce.pms.system.custservice.vo.CustEventNatureVO;
import com.sitechasia.webx.core.support.Page;
/**
 * 描述：测试 AbstractCustomerEventServiceImpl
 * @author 王浩羽
 *
 */
public class AbstractCustomerEventServiceImplT extends TestCase
{

	TestServiceImpl serviceImpl = new TestServiceImpl();
	private CustEventNatureVO natureVO ;
	private CustEventNatureDO natureDO ;

	//常量数据
	private final Long CURRENT_ID = 2008L;
	private final String CURRENT_NAME = "oldName";
	private final String CURRENT_REMARK = "oldRemark";
	private final short CURRENT_SEQUENCE = (short)1;
	
	private final Long NEW_ID = 2009L;
	private final String NEW_NAME = "newName";
	private final String NEW_REMARK = "newRemark";
	private final short NEW_SEQUENCE = (short)2;
	@Before
	public void setUp() throws Exception
	{
		natureVO = new CustEventNatureVO();
		natureDO = new CustEventNatureDO();
		
		natureDO.setKeyword(CURRENT_ID);
		natureDO.setName(CURRENT_NAME);
		natureDO.setRemark(CURRENT_REMARK);
		natureDO.setSequence(CURRENT_SEQUENCE);
		
		natureVO.setKeyword(NEW_ID);
		natureVO.setName(NEW_NAME);
		natureVO.setRemark(NEW_REMARK);
		natureVO.setSequence(NEW_SEQUENCE);
	}


	@After
	public void tearDown() throws Exception
	{
	}

	public void testGetVClassType(){
		String v = serviceImpl.getVClassType().getSimpleName();
		assertEquals(CustEventNatureVO.class.getSimpleName(), v);
	}
	
	public void testGetDClassType(){
		String d = serviceImpl.getDClassType().getSimpleName();
		assertEquals(CustEventNatureDO.class.getSimpleName(), d);
	}
	
	@Test
	public void testAssembleD2VDV()
	{
		assertFalse(natureDO.getName().equals(natureVO.getName()));
		serviceImpl.assembleD2V(natureDO, natureVO);
		assertEquals(natureDO.getName(), natureVO.getName());
		
		CustEventNatureVO newNatureVO = serviceImpl.assembleD2V(natureDO, null);
		assertEquals(natureDO.getKeyword(), newNatureVO.getKeyword());
		assertEquals(natureDO.getName(), newNatureVO.getName());
		assertEquals(natureDO.getRemark(), newNatureVO.getRemark());
		assertEquals(natureDO.getSequence(), newNatureVO.getSequence());
	}


	@Test
	public void testAssembleV2DVD()
	{
		assertFalse(natureVO.getName().equals(natureDO.getName()));
		serviceImpl.assembleV2D(natureVO, natureDO);
		assertEquals(natureVO.getName(), natureDO.getName());
		
		CustEventNatureDO newNatureDO = serviceImpl.assembleV2D(natureVO, null);
		assertEquals(natureVO.getKeyword(), newNatureDO.getKeyword());
		assertEquals(natureVO.getName(), newNatureDO.getName());
		assertEquals(natureVO.getRemark(), newNatureDO.getRemark());
		assertEquals(natureVO.getSequence(), newNatureDO.getSequence());
	}



	@Test
	public void testAssembleDOList2VOList()
	{
		List<CustEventNatureDO> dOList = new ArrayList<CustEventNatureDO>();
		List<CustEventNatureVO> vOList1 = serviceImpl.assembleDOList2VOList(dOList);
		assertTrue(0==vOList1.size());
		final int expectedSize = 5;
		for(int i = 0; i < expectedSize; i++)
		{
			CustEventNatureDO do1 = new CustEventNatureDO();
			do1.setKeyword(new Long(i));
			do1.setName("name"+i);
			do1.setRemark("remark"+i);
			do1.setSequence((short)i);
			dOList.add(do1);
		}
		List<CustEventNatureVO> vOList2 = serviceImpl.assembleDOList2VOList(dOList);
		assertTrue(expectedSize == vOList2.size());
		for(int i = 0; i < expectedSize; i++)
		{
			assertEquals(dOList.get(i).getName(), vOList2.get(i).getName());
			assertEquals(dOList.get(i).getRemark(), vOList2.get(i).getRemark());
			assertTrue(dOList.get(i).getKeyword() == vOList2.get(i).getKeyword());
			assertTrue(dOList.get(i).getSequence() == vOList2.get(i).getSequence());
		}
	}
	
	private class TestServiceImpl extends AbstractCustomerEventServiceImpl<CustEventNatureVO, CustEventNatureDO>
	{

		@Override
		protected CustEventNatureDO findObjectDOById(Long id)
		{
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		protected Page queryDOListByPage(SearchVO searchVO)
		{
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		protected boolean isNameExisit(String name)
		{
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		protected String getNameExisitExceptionInoKey()
		{
			// TODO Auto-generated method stub
			return null;
		}
		
	}
}
